package com.lzxuni.modules.weather.controller;


import com.alibaba.fastjson.JSON;
import com.lzxuni.common.utils.R;
import com.lzxuni.common.utils.StringUtils;
import com.lzxuni.modules.common.controller.BaseController;
import com.lzxuni.modules.system.service.BaseDataItemService;
import com.lzxuni.modules.weather.entity.WeatherInfo;
import com.lzxuni.modules.weather.service.WeatherInfoAnalyseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 天气信息_分析 前端控制器
 * </p>
 *
 * @author LaoNa
 * @since 2020-11-27
 */
@RestController
@RequestMapping("/Weather/InfoAnalyse")
public class WeatherInfoAnalyseController extends BaseController {

    @Autowired
    private WeatherInfoAnalyseService weatherInfoAnalyseService;

    @Autowired
    private BaseDataItemService baseDataItemService;


    private String templatesPath = "/Weather/Analyse";

    //日天气分析主页面
    @RequestMapping("/IndexDay")
    public ModelAndView indexDay() {
        ModelAndView mv = new ModelAndView(templatesPath + "/index_day");
        return mv;
    }

    @RequestMapping("/getDayEcharts")
    public Object getDayEcharts(WeatherInfo weatherInfo) {
        if (weatherInfo != null) {
            if (StringUtils.isBlank(weatherInfo.getWeatherItem())) {
                weatherInfo.setWeatherItem("air_temperature");
            }
            if (weatherInfo.getWeatherItem().equals("remarks")) {
                return R.ok().put("data", JSON.toJSONString(weatherInfoAnalyseService.queryDayRemarksList(weatherInfo)));

            } else {
                return R.ok().put("data", JSON.toJSONString(weatherInfoAnalyseService.queryDayList(weatherInfo)));
            }
        }
        return R.ok().put("data", JSON.toJSONString("[]"));
    }


    //日天气分析主页面
    @RequestMapping("/IndexHour")
    public ModelAndView indexHour() {
        ModelAndView mv = new ModelAndView(templatesPath + "/index_hour");
        return mv;
    }

    @RequestMapping("/getHourEcharts")
    public Object getHourEcharts(WeatherInfo weatherInfo) {
        if (weatherInfo != null) {
            if (StringUtils.isBlank(weatherInfo.getWeatherItem())) {
                weatherInfo.setWeatherItem("air_temperature");
            }
            if (weatherInfo.getWeatherItem().equals("remarks")) {
                return R.ok().put("data", JSON.toJSONString(weatherInfoAnalyseService.queryHourRemarksList(weatherInfo)));

            } else {
                return R.ok().put("data", JSON.toJSONString(weatherInfoAnalyseService.queryHourList(weatherInfo)));
            }
        }
        return R.ok().put("data", JSON.toJSONString("[]"));
    }


}
